<template>
	<view class="shop-car">
		<view class="shopcar-header">
			<text>购物车</text>
			<text>管理</text>
		</view>
		<view class="shop-car-list">
			<view class="shop-car-item" v-for="item in goodsList" :key="item.uid">
				<checkbox-group class="shop-car-checkbox">
					<checkbox value="cb"/>
				</checkbox-group>
				<image class="shop-car-image" :src="item.imgurl" mode=""></image>
				<view class="shop-car-info">
					<text class="header">{{item.goodsName}}</text>
					<view class="goods-size">{{item.goodsSize}}</view>
					<view class="pay-number">
						<view class="pay">￥{{item.goodsPay}}</view>
						<view class="number">
							<view class="button" @click="subtract()">-</view>
							<view class="show-number">{{showNumber}}</view>
							<view class="button" @click="add()">+</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="shop-car-footer">
			<checkbox-group class="all-checked">
				<label>
					<checkbox value="cb"/>全选
				</label>
			</checkbox-group>
			<view class="all-plus">
				<view>
					合计:<text>￥0</text>
				</view>
				<button>结算(0)</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showNumber: 1,
				goodsList:[]
			};
		},
		onLoad() {
			this.getGoodsList()
		},
		methods: {
			subtract() {
				this.showNumber--
				if (this.showNumber <= 0) {
					alert("至少为一件");
					this.showNumber = 1
				}
			},
			add() {
				this.showNumber++
			},
			getGoodsList(){
				const goodsList = require("../../utils/shopcar.json");
				console.log(goodsList)
				this.goodsList = goodsList.list
					
			}
		}
	}
</script>

<style lang="scss">
	.shop-car {
		width: 710rpx;
		margin: 0 auto;
		position: relative;

		.shopcar-header {
			margin-top: 113rpx;
			display: flex;
			justify-content: space-between;
			margin-bottom: 50rpx;

			text {
				&:first-child {
					font-size: 42rpx;
					color: #000;
					font-weight: bold;
				}
			}
		}

		.shop-car-list {
			.shop-car-item {
				height: 200rpx;
				display: flex;
				justify-content: space-around;
				margin: 20rpx 0; 
				.shop-car-checkbox {
					margin-top: 50rpx;
				}

				.shop-car-image {
					width: 400rpx;
					height: 200rpx;
					margin: 0 21rpx;
				}

				.shop-car-info {
					.header {
						font-size: 34rpx;
						width: 200px;
						word-break: break-all;
						text-overflow: ellipsis;
						display: -webkit-box;
						/** 将对象作为伸缩盒子模型显示 **/
						-webkit-box-orient: vertical;
						/** 设置或检索伸缩盒对象的子元素的排列方式 **/
						-webkit-line-clamp: 2;
						/** 显示的行数 **/
						overflow: hidden;
						/** 隐藏超出的内容 **/

					}

					.goods-size {
						font-size: 22rpx;
						width: 180rpx;
						height: 30rpx;
						text-align: center;
						background: #eee;
						margin: 17rpx 0;
					}

					.pay-number {
						display: flex;
						justify-content: space-between;

						.pay {
							color: #fe9766;
						}

						.number {
							width: 30%;
							display: flex;
							justify-content: space-between;
							text-align: center;

							.button {
								display: block;
								width: 50rpx;
								height: 50rpx;
								background-color: #eee;
							}

							.show-number {
								width: 50%;
							}
						}
					}
				}
			}
		}

		.shop-car-footer {
			width: 100%;
			height: 100rpx;
			position: fixed;
			bottom: 50px;
			left: 0;
			display: flex;
			justify-content: space-between;
			line-height: 100rpx;
			box-sizing: border-box;
			border-top: 1px solid #eee;
			.all-checked{
				margin: 0 10rpx;
			}
			.all-plus{
				display: flex;
				justify-content: space-around;
				view{
					text{
						color: #fe9766;
					}
				}
				button{
					height: 80rpx;
					line-height: 80rpx;
					margin: 10rpx 10rpx;
					background-color: #007AFF;
					color: #FFFFFF;
				}
			}
		}
	}
</style>
